<template>
	<view class="baozhengjin">
		<view class="header">
			<view class="icon">
				<text class="iconfont icon-bao" ></text>
			</view>
			<view class="txt">
				诚信保证金
			</view>
		</view>
		<view class="content" v-if="bzj != 1"> 
			<view class="content_title">
				加入保证金计划的优势
			</view>
			<view class="itemlist">
				1: 加入诚信保证金计划,系统将优先推送!
			</view>
			<view class="itemlist">
				2: 加入诚信保证金计划,免除客户后顾之忧!
			</view>
			
			<view class="btnbox">
				<button style="background-color: #007AFF; color: #fff;" @click="join">加入保证金计划</button>
			</view>
		</view>
		<!-- 已加入 -->
		<view class="access" v-else>
			<view class="img">
				<text class="iconfont icon-tongguo"></text>
			</view>
			<view class="infotxt">
				您已成功加入保证金计划!
			</view>
			<view class="btnbox" style="text-align: center;margin-top: 30rpx;">
				<van-button type="primary" @click="goIndex">去首页看看</van-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isAccess: false,
				bzj: "",
			}
		},
		computed: {
			token() {
				return this.$store.state.token;
			}
		},
		onLoad() {
			this.hasBaozheng()
		},
		methods: {
			// 查看用户是否交过保证金
			async hasBaozheng() {
				let res = await this.$Request("POST", "/order/isdeposit",{ token: this.token })
				let code = res.data.code 
				 console.log(res);
				if(code == 202) {
					this.bzj = res.data.data
				} 
			},
			// 去首页
			goIndex() {
				uni.switchTab({
					url:"/pages/index/index"
				})
			},
			// 加入保证金
			async join() {
				console.log(this.token);
				let order = await this.$Request("POST", "/order/faith_deposit", { token: this.token })
				console.log(order);
				uni.requestPayment({
					timeStamp: order.data.timeStamp,
					nonceStr: order.data.nonceStr,
					package: order.data.package ,
					paySign: order.data.paySign,
					signType:"MD5",
					success(e) {
						console.log(e);
						let status = e.errMsg
						if(status == "requestPayment:ok") {
							uni.showToast({
								title: "支付成功",
								icon:"success"
							})
						}
					},
					fail(err) {
						console.log(err);
					}
				})
			}
			
		},
	}
</script>

<style scoped lang="scss">
	.baozhengjin {
		width: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		.header {
			width: 100%;
			display: flex;
			align-items:  center;
			justify-content: center;
			color: #007AFF;
			.icon {
				margin-right: 10rpx;
			}
		}
		.content {
			width: 100%;
			padding: 20rpx 30rpx;
			box-sizing: border-box;
			color: #007AFF;
			font-size: 24rpx;
			.content_title {
				font-size: 30rpx;
				font-weight: bold;
				color: red;
				height: 60rpx;
				line-height: 60rpx;
			}
			.itemlist {
				height: 40rpx;
				line-height: 40rpx;
			}
			.btnbox {
				margin: 20rpx auto;
			}
		}
		.access {
			width: 100%;
			box-sizing: border-box;
			padding-top: 20%;
			.img {
				width: 100%;
				text-align: center;
				text {
					font-size: 300rpx;
					color: #007AFF;
				}
			}
			.infotxt {
				color: #007AFF;
				text-align: center;
				height: 60rpx;
				line-height: 60rpx;
			}
		}
	}
</style>
